home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / local / uiResources / share.php < prev    next >
PHP Script  |  2010-05-19  |  24KB  |  700 lines

  1. <?php
  2. /**
  3.  * User Interface shared resources configuration
  4.  *
  5.  * PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category   NA
  14.  * @package    NA
  15.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  16.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  17.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  18.  * @version    CVS: $Id:$
  19.  * @link       http://www.weezo.net
  20.  * @since      File available since Release 2.0.0
  21.  */
  22.  
  23. /**
  24.  * @desc Used for falphabetical sort of tree nodes
  25.  *
  26.  * @param array $a
  27.  * @param array $b
  28.  * @return integer
  29.  */
  30. function cmp($a,$b){
  31.     $a=strtolower($a['label']);
  32.     $b=strtolower($b['label']);
  33.     if ($a==$b) return 0;
  34.     return ($a < $b) ? -1 : 1;
  35. }
  36.  
  37. /**
  38.  * @desc Insert new resource form dedicated to file sharing (called from windows context menu) - See rcNewResourceForm function for details
  39.  *
  40.  */
  41. function showNewFileResourceForm(){
  42.     global $resources;
  43.     require_once(INCLUDE_DIR.'explorerFunctions.php');
  44.  
  45.     $files=cfGGetVar('uiResourceShellAction');
  46.  
  47.     // Save for use if user confirmed resource creation (newResType/newResSubType async commands)
  48.     cfGSetVar('uiResourceShellFiles',$files,true);
  49.  
  50.     // And destroy uiResourceShellAction so next sync refresh doesn't display form
  51.     cfGSetVar('uiResourceShellAction',false,true);
  52.  
  53.     $possible=cfArrayValuesToKeys(array('file1','multimedia','video','music1','music3','photo1'));
  54.  
  55.     // If selected file is a directory, allow everything
  56.     if(count($files)==1 && is_dir($files[0])){
  57.  
  58.     }
  59.     else{
  60.         // music3 (music database): only valid for one single directory
  61.         unset($possible['music3']);
  62.  
  63.         // Browse shared files to determine incompatible resources
  64.         foreach ($files as $file){
  65.             if(!is_dir($file)) switch (efFileType($file)){
  66.                 case 'audio':
  67.                     unset($possible['photo1']);
  68.                     unset($possible['photo2']);
  69.                     unset($possible['photo3']);
  70.                     unset($possible['video']);
  71.                     break;
  72.                 case 'video':
  73.                     unset($possible['photo1']);
  74.                     unset($possible['photo2']);
  75.                     unset($possible['photo3']);
  76.                     unset($possible['music1']);
  77.                     unset($possible['music3']);
  78.                     break;
  79.                 case 'image':
  80.                     unset($possible['video']);
  81.                     unset($possible['music1']);
  82.                     unset($possible['music3']);
  83.                     break;
  84.                 default:
  85.                     unset($possible['photo1']);
  86.                     unset($possible['photo2']);
  87.                     unset($possible['photo3']);
  88.                     unset($possible['music1']);
  89.                     unset($possible['music3']);
  90.                     unset($possible['video']);
  91.                     unset($possible['multimedia']);
  92.             }
  93.         }
  94.     }
  95.  
  96.     // Set shown type & subtypes nodes on new resource form
  97.     $shownNodes='';
  98.     foreach ($possible as $v) $shownNodes.=(($shownNodes)?',':'{').'"'.addslashes($v).'":1';
  99.     $shownNodes='{"explorer":'.$shownNodes.'}}';
  100.  
  101.     // And set form to show onload
  102. ?>
  103. <script type="text/javascript">
  104. //alert(wl.arrayPack(<?php echo $shownNodes;?>))
  105. wl.UICommand('webPopup:/local/uiResources/shareNew.php?shownNodes='+wl.arrayPack(<?php echo $shownNodes;?>),false,'createResourceProceed');
  106. </script>
  107. <?php
  108. }
  109.  
  110. /**
  111.  * Display a page showing all resources for a given type
  112.  *
  113.  */
  114. function displayResourceTypeLayoutPage($type,$subType=false){
  115.     global $resources;
  116.  
  117.     // HTML Head
  118.     cfInsertHEAD(false);
  119.     ?>
  120. <script type="text/javascript">
  121. function newRes(type,subType){parent.createResource(type,subType)}
  122. </script>
  123. </head><body style="padding-right:1.5em;padding-left:1.5em;">
  124.     <?php
  125.     $typeIconSrc='/res/'.$type.'/resourceIcon.png';
  126.     if(!is_file($typeIconSrc))    $typeIconSrc='/res/'.$type.'/resourceIcon.gif';
  127.  
  128.  
  129.     /**
  130.      * Misc resources: display install button
  131.      */
  132.     if($type=='misc' && cfIsInApp()){
  133.         $installButton=outButton(cfCaption('resMisc').'...',"javascript:wl.UICommand('pluginmanagement')",outIcon('plugins'));
  134.     }
  135.     else $installButton='';
  136.  
  137.     // Title
  138.     echo outDivFrame('frame1');
  139.     $img=outImage($typeIconSrc,false,false,'width:32;height:32;margin-right:0.5em;vertical-align:middle');
  140.     $img='';
  141.     echo outFrameHeaderTable('frame1Header','<span class="uiTabTitle">'.$img.(cfCaption('res'.ucfirst($type))).'</span>',$installButton);
  142.  
  143.  
  144.     // Search type's resources
  145.     $resourcesDefinitions=cfMGetVar('weezoResourcesDefinitions');
  146.  
  147.  
  148.  
  149.     /**
  150.      * Browse subtypes
  151.      */
  152.     if(isset($resourcesDefinitions[$type])) foreach ($resourcesDefinitions[$type] as $rSubType=>$memVarName){
  153.         // If a single subType should be displayed, skip all others
  154.         if($subType && $subType!=$rSubType) continue;
  155.  
  156.         $rData=rcGetResourceDefinition($type,$rSubType);
  157.         if(isset($rData['describer']['deprecated'])) continue;
  158.  
  159.         echo outDivFrame('frame3 solidBorder',false,(($subType)?'margin-top:5em':''));
  160.         $rPath='/res/'.$type.'/'.$rSubType;
  161.         $icoPath=$rData['resourceIcon'];
  162.  
  163.         // Set node
  164.         $r=outButton(cfCaption('adminResourceCreate'),"javascript:newRes('".$type."','".$rSubType."')",outIcon('new'));
  165.  
  166.         // If "singleInstance" set, check if this resource has already been created
  167.         if(@$rData['describer']['singleInstance']){
  168.             if(is_array($resources)) foreach ($resources as $rid=>$res) if($res['type']==$type && $res['subType']==$rSubType){
  169.                 $r=outButton(cfCaption('adminResourceCreate'),"javascript:newRes('".$type."','".$rSubType."')",outIcon('new'),false,false,false,false,true);
  170.                 break;
  171.             }
  172.         }
  173.  
  174.         // Icon, name and new resource button
  175.         echo outFrameHeaderTable('frame2Header',outImage($icoPath,false,false,'margin-right:0.5em;vertical-align:middle').$rData['name'],$r);
  176.  
  177.         // Screenshot
  178.         echo '<center>';
  179.         if(file_exists(cfAppDocRoot().$rPath.'/preview.jpg')) echo outImage($rPath.'/preview.jpg');
  180.         else echo '<div class="frame3" style="width:100px;height:100px;padding-top:45px">'.cfCaption('genNoPreview').'</div>';
  181.         echo '</center>';
  182.  
  183.         // Description
  184.         echo '<div class="frame2" style="margin:1.5em;padding:1em">'.$rData['description'].'</div>';
  185.         echo '</div>';
  186.     }
  187.     exit;
  188. }
  189.  
  190. /**
  191.  * @desc Generate resources tree
  192.  *
  193.  * @return unknown
  194.  */
  195. function shareResourcesTree($selectedFile){
  196.     global $resources;
  197.  
  198.     $tree=array('ico'=>outIcon('resources'),'path'=>'top','label'=>'','sub'=>array());
  199.     $firstNode=false;
  200.     $folding=cfExplode2Levels('/',':',cfGGetVar('uiResouceTreeFolding'));
  201.  
  202.     $defaultFound=0;
  203.     $nb=0;
  204.  
  205.     $existingResources=cfMGetVar('weezoResourcesDefinitions');
  206.  
  207.     // Regroup resources by type
  208.     foreach (array('explorer','bookmarks','webcam','blog','tv','administration','website','misc') as $type){
  209.         // Init type's node
  210.         $tree['sub'][$type]=array(
  211.             'ico'=>'/res/'.$type.'/resourceIconSmall.'.((file_exists(cfAppDocRoot().'/res/'.$type.'/resourceIconSmall.png'))?'png':'gif'),
  212.             'label'=>'<b>'.cfCaption('res'.ucfirst($type)).'</b>',
  213.             'sub'=>array())
  214.             +((isset($folding[$type]) && $folding[$type])?array():array('unfolded'=>true))
  215.             +(($type==$selectedFile)?array('selected'=>true):array())
  216.             ;
  217.         if($type==$selectedFile) $defaultFound=1;
  218.  
  219.         $createdTypes=array();
  220.  
  221.         // Browse resources
  222.         foreach ($resources as $rid=>$res) if($res['type']==$type) {
  223.             $icoPath=$res['definition']['resourceIconSmall'];
  224.             $filename=$res['resourceFilename'];
  225.             $createdTypes[$res['subType']]=1;
  226.             // Set type's sub nodes
  227.             $tree['sub'][$type]['sub'][$filename]=array(
  228.                 'ico'=>$icoPath,
  229.                 'label'=>cfUTF8Encode($res['name'],false),
  230.                 'tag'=>$res['subType'],
  231.                 'sub'=>array()
  232.             );
  233.  
  234.             if(!$defaultFound && $filename==$selectedFile) {
  235.                 $tree['sub'][$type]['sub'][$filename]['selected']=true;
  236.                 $defaultFound=1;
  237.             }
  238.             elseif (!$firstNode) $firstNode=array($type,$filename);
  239.         }
  240.  
  241.         // Alphabetically sort type's resources
  242.         uasort($tree['sub'][$type]['sub'],'cmp');
  243.  
  244.         // Browse existing resources to append inexisting ones
  245.         if(cfGGetVar('uiShowNonCreatedResources')){
  246.             if(isset($existingResources[$type])) foreach (@$existingResources[$type] as $subType=>$tmpId) if(!isset($createdTypes[$subType])){
  247.                 $rDef=cfMGetVar($tmpId);
  248.                 if(@$rDef['describer']['deprecated']) continue;
  249.  
  250.                 // Set type's sub nodes
  251.                 $tree['sub'][$type]['sub'][$subType]=array(
  252.                     'faded'=>1,
  253.                     'ico'=>$rDef['resourceIconSmall'],
  254.                     'label'=>(rcResourceCaptionUTF8($type,$subType)).
  255.                         outImage(outIcon('minus'),false,'title="'.cfCaption('genHide').'" onclick="hideNCR()"','vertical-align:middle;cursor:pointer;width:16px;margin-left:0.5em').
  256.                         outImage(outIcon('newVS'),false,'title="'.cfCaption('adminResourceCreate').'" onclick="createResource(\''.$type.'\',\''.$subType.'\')"','vertical-align:middle;cursor:pointer;width:16px;margin-left:0.5em'),
  257.                     'sub'=>array()
  258.                 );
  259.             }
  260.         }
  261.  
  262.         //if(count($tree['sub'][$type]['sub'])==0) $tree['sub'][$type]['faded']=true;
  263.         //if(count($tree['sub'][$type]['sub'])==0) $tree['sub'][$type]['label']='youpi<br>   ligne2<br>   ligne3';
  264.         if(0 && count($tree['sub'][$type]['sub'])==0)
  265.             $tree['sub'][$type]['sub']['default']=array(
  266.                 'ico'=>outIcon('resNo'),
  267.                 'label'=>cfCaption('resNoResource').'...',
  268.                 'tag'=>$res['subType'],
  269.                 'disabled'=>1,
  270.                 'sub'=>array()
  271.             );
  272.  
  273.     }
  274.     // If default selected not found, select 1st resource
  275.     if(!$defaultFound && $firstNode) $tree['sub'][$firstNode[0]]['sub'][$firstNode[1]]['selected']=true;
  276.  
  277.     $treeView=new treeView('resTree');
  278.     $treeView->phpTree=$tree;
  279.     $treeView->selectFunction='treeSelectRes';
  280.     $treeView->toggleFoldFunction='treeChangeFolding';
  281.     $treeView->rightClickFunction='treeRightClick';
  282.     return $treeView->HTML('frame3 solidBorder',false,false,'width:199px;height:382px');
  283. }
  284.  
  285. /**
  286.  * @desc Generate:
  287.  *         - a PHP array of resources ($resources),
  288.  *         - a javascript array (=PHP string) of users-resouces association ($urArray),
  289.  *         - a javascript array (=PHP string) of users ($usersArray),
  290.  *         - a javascript array (=PHP string) of resources ($resourcesArray),
  291.  *         - get administrator acount UID ($adminUID)
  292.  *
  293.  */
  294. function shareGenerateUsersAndResourcesArrays(){
  295.     global $resources;
  296.     global $urArray;
  297.     global $usersArray;
  298.     global $resourcesArray;
  299.     global $adminUID;
  300.  
  301.     // Generate an array of user id=>user name
  302.     $users=cfUsersConfigs();
  303.     $usersArray='';
  304.     $adminUID='';
  305.     foreach ($users as $uid=>$user) {
  306.         $usersArray.=',"'.$uid.'":"'.addslashes(cfUTF8Encode($user->getVar('name'))).'"';
  307.         if($user->isAdministrator()) $adminUID=$uid;
  308.     }
  309.     $usersArray='{'.substr($usersArray,1).'}';
  310.  
  311.  
  312.     // Retreive resources from memory
  313.     $resources=array();
  314.     $resourcesArray='';
  315.     foreach (cfMGetVar('weezoResourcesList') as $rid=>$filename){
  316.         $resources[$rid]=cfMGetVar('weezoResData'.$rid);
  317.         $resourcesArray.=',"'.$filename.'":"'.addslashes(cfUTF8Encode($resources[$rid]['name'])).'"';
  318.     }
  319.     $resourcesArray='{'.substr($resourcesArray,1).'}';
  320.  
  321.  
  322.     $urArray=''; // Generate a JS array listing users bound to resources: Array(filename:Array(uid1,uid2...),... )
  323.     $ruArrayPHP=array(); // And its counterpart in PHP
  324.     foreach ($resources as $rid=>$res){
  325.         $filename=$res['resourceFilename'];
  326.         $urArray.=",'".$filename.'\':Array(';
  327.         $nb=0;
  328.         $ruArrayPHP[$filename]=array();
  329.         foreach ($users as $uid=>$user){
  330.             foreach ($user->getResources() as $rid=>$rfn) if($rfn==$filename){
  331.                 $urArray.=(($nb)?',':'')."'".$uid."'";
  332.                 $nb++;
  333.                 $ruArrayPHP[$filename][$uid]=1;
  334.             }
  335.         }
  336.         $urArray.=')';
  337.     }
  338.     $urArray='{'.substr($urArray,1).'}';
  339. }
  340.  
  341. // Indicate an in-application display
  342. $_ENV['configurationEnvironment']='application';
  343.  
  344. if(!isset($_GET['configLng'])) $_GET['configLng']=cfGGetVar('language');
  345.  
  346. // Create fake resource to enable use of cfRGet/SetVar functions
  347. cfRCreateFakeResource();
  348.  
  349. $selectedFile=cfGGetVar('uiResourceSelected');
  350.  
  351. require_once(INCLUDE_DIR.'resourceConfigFunctions.php');
  352. require_once(INCLUDE_DIR.'outputFunctions.php');
  353.  
  354.  
  355.  
  356. /**
  357.  ***************************************************************************************************************************
  358.  * Process Async command
  359.  ***************************************************************************************************************************
  360.  */
  361. if(cfIsAsync()){
  362.     cfAsyncHeader();
  363.     // Selected resource update
  364.     if(isset($_POST['uiResourceSelected']) && $selectedFile!=$_POST['uiResourceSelected']){
  365.         cfGUpdateVar('uiResourceSelected',$_POST['uiResourceSelected']);
  366.     }
  367.     // Resource tree folding update
  368.     if(isset($_POST['uiResouceTreeFolding'])){
  369.         cfGUpdateVar('uiResouceTreeFolding',$_POST['uiResouceTreeFolding']);
  370.     }
  371.     // Hide not-yet-created resources
  372.     if(isset($_POST['uiShowNonCreatedResources'])){
  373.         cfGUpdateVar('uiShowNonCreatedResources',(int)$_POST['uiShowNonCreatedResources']);
  374.         echo cfAsyncXMLJSaction('wl.goURL()');
  375.     }
  376.  
  377.     /**
  378.      *  Create new resource of passed type/subType
  379.      */
  380.     if(isset($_POST['newResType']) && isset($_POST['newResSubType'])){
  381.  
  382.         // Using files passed by windows context menu
  383.         if(isset($_POST['useFilesList']) && ($files=cfGGetVar("uiResourceShellFiles"))){
  384.             // If single directory, create classical path var
  385.             if(count($files)==1 && is_dir($files[0])){
  386.                 $resourceData=array('path'=>$files[0],'subFoldersIncluded'=>true,'sharedMode'=>'folder');
  387.             }
  388.             // Else create list-of-files resource
  389.             else{
  390.                 $resourceData=array('path'=>'*appDir*/shared','subFoldersIncluded'=>true,'sharedMode'=>'list');
  391.                 $resourceData+=array('sharedItems'=>implode('|',$files));
  392.             }
  393.         }
  394.         else $resourceData=array();
  395.  
  396.         // If passed name
  397.         if(isset($_POST['resourceName'])) {
  398.             $resourceData['name']=cfUTF8Decode($_POST['resourceName'],true,false,false);
  399.             // Double UTF8 decode if request comming from standalone
  400.             // (wl.arrayPack does an internal UTF8 encoding to UI, which injects as-is into an <input>)
  401.             if(@$_POST['standalone']) $resourceData['name']=cfUTF8Decode($resourceData['name'],true,false,false);
  402.         }
  403.  
  404.         // Create Resource
  405.         if($filename=rcCreateResource($_POST['newResType'],$_POST['newResSubType'],$resourceData)){
  406.             // Bind resource to selected users
  407.             if(isset($_POST['users'])) rcResourceAddToUsers($filename,explode('/',$_POST['users']));
  408.             cfGUpdateVar('uiResourceSelected',$filename);
  409.             echo cfAsyncXMLJSaction('D.location.reload()');
  410.         }
  411.     }
  412.  
  413.     // Delete resource
  414.     if(isset($_POST['deleteResource']) && file_exists(cfAppDataDir().'/'.$_POST['deleteResource'])){
  415.         // Delete resource file and inform application
  416.         rcDeleteResource($_POST['deleteResource']);
  417.     }
  418.  
  419.     // Remove resource from user
  420.     if(isset($_POST['removeResourceFromUser']) && isset($_POST['resource']) && isset($_POST['user'])){
  421.         $updatedUsers=array();
  422.         // Browse users to find concerned user(s)
  423.         foreach (cfUsersConfigs() as $uid=>$user) if($_POST['user']=='all' || $_POST['user']==$uid) {
  424.             $user->removeResource($_POST['resource']);
  425.             $user->save();
  426.         }
  427.         require_once(INCLUDE_DIR.'initFunctions.php');
  428.         ifResetResourcesUsers();
  429.         // Update bound users list in resource panel by async refreshing display
  430.         echo cfAsyncXMLJSaction('toggleUserDone("'.$_POST['resource'].'","'.$_POST['user'].'")');
  431.     }
  432.  
  433.     // Add a resource to user
  434.     if(isset($_POST['connectResourceToUser']) && isset($_POST['resource']) && isset($_POST['user'])){
  435.         rcResourceAddToUsers($_POST['resource'],$_POST['user']);
  436.         // Update bound users list in resource panel by async refreshing display
  437.         echo cfAsyncXMLJSaction('toggleUserDone("'.$_POST['resource'].'","'.$_POST['user'].'")');
  438.     }
  439.     die(cfAsyncFooter());
  440. }
  441.  
  442.  
  443.  
  444. /**
  445.  ***************************************************************************************************************************
  446.  * Display a page showing all resources for a given type
  447.  ***************************************************************************************************************************
  448.  */
  449. if(isset($_GET['resourceTypeLayout']))    displayResourceTypeLayoutPage($_GET['resourceTypeLayout'],@$_GET['resourceSubTypeLayout']);
  450.  
  451. // Erase temporary context-menu selected files
  452. cfGSetVar('uiResourceShellFiles',false,true);
  453.  
  454.  
  455. shareGenerateUsersAndResourcesArrays();
  456.  
  457. /**
  458.  ***************************************************************************************************************************
  459.  * Insert page HEADER
  460.  ***************************************************************************************************************************
  461.  */
  462. ob_start();
  463. cfInsertHEAD(false);
  464. echo cfScriptLink('winClient.js');
  465. ?>
  466. </head>
  467. <body style="margin:0;padding:0" onload="treeSelectRes();initDone=1">
  468. <?php
  469. echo cfScriptLink('wz_dragdrop.js');
  470. ?>
  471. <script type="text/javascript">
  472. var adminUID="<?php echo $adminUID;?>";
  473. var users=<?php echo $usersArray;?>;
  474. var resources=<?php echo $resourcesArray;?>;
  475. var ur=<?php echo $urArray;?>;
  476. var initDone=0;
  477.  
  478. // Tree folding changed
  479. function treeChangeFolding(node){
  480.     var tn=node.treeView().tree['sub'],n,o='',p;
  481.     for(e in tn) {
  482.         n=new treeNode('resTree_'+tn[e]['path'])
  483.         p=n.getPath();
  484.         o+=(o?'/':'')+p.substr(p.lastIndexOf('/')+1)+':'+(n.isFolded()?1:0);
  485.     }
  486.     if(initDone) sendData('uiResouceTreeFolding='+o)
  487. }
  488.  
  489. // Resource clicked
  490. function treeSelectRes(node,noToggleFold){
  491.     var save=node?1:0;
  492.     if(!node) node=treeViews["resTree"].selectedNode;
  493.  
  494.     var path=node.getPath().split('/');
  495.  
  496.     selectedResource=path[path.length-1];
  497.     if(!save) node.focusView();
  498.     if(!save || !node.isSelected()) {
  499.         node.setSelected();
  500.         // Type
  501.         if(path.length==2) {
  502.             if(!noToggleFold && node.isFolded()) node.toggleFold();
  503.             dgi('resourceConfigFrame').src='<?php echo $_SERVER['PHP_SELF'];?>?resourceTypeLayout='+selectedResource;
  504.         }
  505.         // Resource subtype
  506.         else if(selectedResource.indexOf('.res')==-1){
  507.             dgi('resourceConfigFrame').src='<?php echo $_SERVER['PHP_SELF'];?>?resourceTypeLayout='+path[1]+'&resourceSubTypeLayout='+selectedResource;
  508.         }
  509.         // Resource
  510.         else{
  511.             dgi('resourceConfigFrame').src='/res/administration/std/resourceConfig.php?resourceConfigFilename='+selectedResource+'&configLng=<?php echo $_GET['configLng'];?>&resourceConfigScript=1';
  512.         }
  513.         if(save) sendData('uiResourceSelected='+selectedResource);
  514.     }
  515.     else if(!noToggleFold && path.length==2) node.toggleFold();
  516. }
  517.  
  518. // Right click menu on resources treeView
  519. function treeRightClick(node){
  520.     var path=node.getPath().split('/');
  521.     if(path.length==2) {
  522.         if(!node.isSelected()) treeSelectRes(node,true)
  523.         var items=Array();
  524.         items[0]=ContextMenuItem("<?php echo outIcon('new');?>","<?php echo cfCaption('resNewResource');?>","createResource('"+path[1]+"')");
  525.  
  526.         var cm=new ContextMenu(items);
  527.         return;
  528.     }
  529.     else{
  530.         var adminUserOnly=0
  531.  
  532.         if(!node.isSelected()) treeSelectRes(node)
  533.  
  534.         selectedResource=path[2];
  535.         var boundUsers=ur[selectedResource];
  536.  
  537.         if(path[1]=='administration') adminUserOnly=1
  538.  
  539.         // Generate context-menu
  540.         var items=Array();
  541.         items[0]=0;
  542.         items[items.length]=ContextMenuItem('sep');
  543.         nbLinked=0;
  544.         for(var u in users){
  545.             if(adminUserOnly && u!=adminUID) continue; // If admin resource, show only administrator
  546.             linked=0;
  547.             for(i=0;i<boundUsers.length;i++) if(boundUsers[i]==u) linked=1;
  548.             nbLinked+=linked;
  549.             items[items.length]=ContextMenuItem((linked)?"<?php echo outIcon('cmChecked');?>":"<?php echo outIcon('v');?>",users[u],'toggleUser(\''+selectedResource+'\',\''+u+'\')');
  550.         }
  551.  
  552.         // Set 1st item (remove from all users)
  553.         if(nbLinked==0) items[0]=ContextMenuItem("<?php echo outIcon('cancelVS');?>","<?php echo cfCaption('resRemoveFromAll');?>",false);
  554.         else items[0]=ContextMenuItem("<?php echo outIcon('cancelVS');?>","<?php echo cfCaption('resRemoveFromAll');?>",'toggleUser(\''+selectedResource+'\',\'all\')');
  555.  
  556.         items[items.length]=ContextMenuItem('sep');
  557.         items[items.length]=ContextMenuItem("<?php echo outIcon('del');?>","<?php echo cfCaption('genDelete');?>",'deleteResource(\''+selectedResource+'\')');
  558.         var cm=new ContextMenu(items);
  559.  
  560.     }
  561. }
  562. // Toggle user association with selected resource
  563. function toggleUser(rid,uid){
  564.     if(uid=='all'){
  565.         ur[rid]=Array();
  566.         sendData('removeResourceFromUser=1&resource='+rid+'&user=all')
  567.     }
  568.     else{
  569.         var found=0;
  570.         for(var i=0;i<ur[rid].length;i++) {
  571.             if(ur[rid][i]==uid){
  572.                 delete(ur[rid][i]);
  573.                 found=1;
  574.                 sendData('removeResourceFromUser=1&resource='+rid+'&user='+uid)
  575.                 break;
  576.             }
  577.         }
  578.         if(!found) {
  579.             ur[rid][ur[rid].length]=uid;
  580.             sendData('connectResourceToUser=1&resource='+rid+'&user='+uid)
  581.         }
  582.     }
  583. }
  584. // Async Called in response to toggleUser
  585. function toggleUserDone(rid,uid){
  586.     try{frames['resourceConfigFrame'].save(1)} catch(e){}
  587. }
  588. // Delete a resource
  589. function deleteResource(rid){
  590.     if(ur[rid].length>1) capt="<?php echo cfCaptionJS('resConfirmDeleteMany');?>";
  591.     else if(ur[rid].length==1) capt="<?php echo cfCaptionJS('resConfirmDeleteOne');?>";
  592.     else capt="<?php echo cfCaptionJS('resConfirmDeleteNo');?>";
  593.  
  594.     //var capt='<?php echo str_replace("'",'',cfCaption('userConfirmDelete'))?>';
  595.     capt=capt.replace(/%1/,resources[rid])
  596.     capt=capt.replace(/%2/,ur[rid].length)
  597.     capt=capt.replace(/<br>/g,"\n")
  598.     if(!confirm(capt)) return;
  599.  
  600.     var n=treeViews["resTree"].selectedNode;
  601.     // Select prev node if existing
  602.     if(n.previousSibling()) treeSelectRes(n.previousSibling())
  603.     // else select next
  604.     else if(n.nextSibling()) treeSelectRes(n.nextSibling())
  605.     // else select parent
  606.     else treeSelectRes(n.parentNode(),1);
  607.  
  608.     // Remove node
  609.     n.remove();
  610.  
  611.     sendData("deleteResource="+rid)
  612. }
  613. // Create a resource.
  614. function createResource(type,subType){
  615.     var shownNodes=false,args='?fromUI=1';
  616.  
  617.     if(subType) {
  618.         args+='&newResType='+type+'&newResSubType='+subType;
  619.     }
  620.     else if(type) {
  621.         shownNodes={};
  622.         shownNodes[type]=1;
  623.         args+='&shownNodes='+wl.arrayPack(shownNodes)
  624.     }
  625.  
  626.     // Open popup in UI
  627.     // Note: this popup is also opened directly by UI by simulating this call
  628.     wl.UIWebPopup('/local/uiResources/shareNew.php'+args,createResourceProceed);
  629. }
  630. function createResourceProceed(r){
  631.     eval('var resConfig='+r);
  632.     resConfig['standalone']=1;
  633.     wl.asr.send(resConfig);
  634. }
  635. // Update name while being modified in resource config
  636. function resourceNameModified(filename,newName){
  637.     var type,sn,sn2,tn;
  638.     for(sn in treeViews["resTree"].tree.sub) {
  639.         type=treeViews["resTree"].tree.sub[sn];
  640.         for(sn2 in type['sub']) if(sn2==filename){
  641.             tn= new treeNode("resTree_"+type['sub'][sn2]['path'])
  642.             tn.setLabel(newName)
  643.             return;
  644.         }
  645.     }
  646. }
  647. // Called when share tab selected/unselected: forward info to configuration iframe
  648. function tabSelected(isSelected,tabName){
  649.     if(frames['resourceConfigFrame'].tabSelected) frames['resourceConfigFrame'].tabSelected(isSelected);
  650. }
  651. function hideNCR(){wl.asr.send({'uiShowNonCreatedResources':0})}
  652. <?php
  653.  
  654. // If a new resource webpopup is requested by UI (by creating "uiResourcesShareOpenNewResource" file into temp dir), do it
  655. if(file_exists(cfAppTempDir().'/uiResourcesShareOpenNewResource')){
  656.     unlink(cfAppTempDir().'/uiResourcesShareOpenNewResource');
  657.     echo 'createResource();';
  658. }
  659. ?>
  660. </script>
  661. <?php
  662.  
  663. // Create treeView
  664.  
  665. // Generate HTML
  666. echo '<div class="frame2 uiLeftFrame" style="width:209px;margin:0;height:100%">';
  667. echo '<div class="uiTabTitle">'.cfCaption('genResources').'</div>';
  668. // New resource button
  669. echo '<center style="margin-bottom:5px">';
  670. echo outBt('<b style="font-weight:bold">'.cfCaption('resNewResource').'</b>',outIcon('new'),"javascript:createResource()",false,false,false,'up',160);
  671. echo '</center>';
  672.  
  673. /**
  674.  * Resources tree
  675.  */
  676. echo '<div id="resTreeOuter">';
  677. echo shareResourcesTree($selectedFile);
  678. echo '</div>'; // treeOuter
  679.  
  680. echo '</div>';
  681. echo '</div>';
  682. ?>
  683. <iframe id="resourceConfigFrame" name="resourceConfigFrame" scrolling="auto" frameborder="0" src="" style="position:absolute;top:4;left:212;width:500;height:446"></iframe>
  684. <?php
  685.  
  686. // New resource form
  687. //rcNewResourceForm();
  688.  
  689. /**
  690.  ***************************************************************************************************************************
  691.  * New Resource requested from context-menu
  692.  ***************************************************************************************************************************
  693.  */
  694. if(cfGGetVar('uiResourceShellAction') && cfGGetVar('uiResourceAccordion')=='share') showNewFileResourceForm();
  695.  
  696. echo cfDragRegisterItems('');
  697. //file_put_contents('C:/P1/share.html',ob_get_contents());
  698. ob_flush();
  699. ?>
  700. </body>